package cc3002;

/**
 * This class stores the health state and the reaction to certain foods. 
 * @author Anibal Llanos Prado
 *
 */
public class HealthState {
	private int state;
	private String foodSaver;
	
	/**
	 * Creates somebodie's Health State with it initial values, starting from a certain state.
	 * @param s The initial state.
	 */
	public HealthState(int s){
		state=s;
		foodSaver="00";
	}
	
	/**
	 * Creates somebodie's Health State with it initial values, starting from "Normal" state.
	 */
	public HealthState(){
		state=3;
		foodSaver="00";
	}
	
	/**
	 * Sets the reaction memory to certain types of Food.
	 * @param good The "good food" memory.
	 * @param bad The "Bad Food" memory.
	 */
	public void setFoodSaver(int good, int bad){
		foodSaver=""+good+bad;
	}
	
	/**
	 * Gets the reaction memory.
	 * @return The reaction memory.
	 */
	public String getFoodSaver(){
		return foodSaver;
	}
	
	/**
	 * Gets the actual Health State.
	 * @return Actual Health State.
	 */
	public int getState(){
		return state;
	}
	
	/**
	 * Sets a new State.
	 * @param  state Desired state.
	 */
	public void setState(int state){
		this.state=state;
	}
	
	/**
	 * Decreases your Health State. If your state reaches to "Dying" you'll die.
	 */
	public void getWorst(){
		assert state!=0:"I should be dead, i can't get even worst";
		if(state!=0)--state;
		assert invariant():"Health State is Corrupted";
	}
	
	/**
	 * Increases your Health State up to Immortal.
	 */
	public void getBetter(){
		assert state!=6:"Can I be better than inmortal?";
		if(state!=6)++state;
		assert invariant():"Health State is Corrupted";
	}
	
	/**
	 * Returns a String describing your Health State in words.
	 * @return The Health State in words.
	 */
	public String toString(){
		assert invariant():"Health State is Corrupted";
		switch(state){
		case 0: return "Dying";
		case 1: return "Really Sick";
		case 2: return "Sick";
		case 3: return "Normal";
		case 4: return "Healthy";
		case 5: return "Really Healthy";
		case 6: return "Inmortal";
		default: return "";
		}
	}
	
	/**
	 * This is the invariant for this class. If everything's well-working, returns true.
	 * @return True if the invariant is valid, otherwise false.
	 */
	private boolean invariant(){
		return state>=0 && state<=6;
	}
	
	/**
	 * Gets the multiplier that will be used when you get calories from Food. It depends on
	 * your current Health State.
	 * @return The corresponding multiplier.
	 */
	public double getFoodMultiplier(){
		switch(state){
		case 0: return 0;
		case 1: return 0.3;
		case 2: return 0.6;
		case 3: return 1;
		case 4: return 1.3;
		case 5: return 1.6;
		case 6: return 2;
		default: return 1;
		}
	}
	
	/**
	 * Gets the multiplier that will be used when you consume calories. It depends on your 
	 * current Health State.
	 * @return The corresponding multiplier.
	 */
	public double getCCMultiplier(){
		switch(state){
		case 0: return 2;
		case 1: return 1.6;
		case 2: return 1.3;
		case 3: return 1;
		case 4: return 0.6;
		case 5: return 0.3;
		case 6: return 0;
		default: return 1;
		}
	}

}
